﻿#include "ITCatTableBase.h"

ITCatTableBase::ITCatTableBase()
    : m_properties{}, isSelected(false), isHot(false), index(-1), tag(nullptr)
{
	for (int i = 0; i < (int)ITCatTablePropertiesEnum::COUNT; i++) {
		m_properties[(ITCatTablePropertiesEnum)i] = 0;
	}
}

DWORD ITCatTableBase::GetProperty(ITCatTablePropertiesEnum propertyKey) const
{
	if (propertyKey == ITCatTablePropertiesEnum::COUNT) return 0;
	auto it = m_properties.find(propertyKey);
	return (it != m_properties.end()) ? it->second : 0;
}

void ITCatTableBase::SetProperty(ITCatTablePropertiesEnum propertyKey, DWORD value)
{
	if (propertyKey == ITCatTablePropertiesEnum::COUNT) return;
	m_properties[propertyKey] = value;
}

const std::map<ITCatTablePropertiesEnum, DWORD> & ITCatTableBase::GetProperties()
{
	return m_properties;
}

void ITCatTableBase::SetProperties(const std::map<ITCatTablePropertiesEnum, DWORD>& properties)
{
	m_properties = properties;
}

void ITCatTableBase::AddStyle(DWORD styleFlags)
{
	DWORD currentStyle = GetProperty(ITCatTablePropertiesEnum::DWSTYLE);
	SetProperty(ITCatTablePropertiesEnum::DWSTYLE, currentStyle | styleFlags);
}

void ITCatTableBase::RemoveStyle(DWORD styleFlags)
{
	DWORD currentStyle = GetProperty(ITCatTablePropertiesEnum::DWSTYLE);
	SetProperty(ITCatTablePropertiesEnum::DWSTYLE, currentStyle & ~styleFlags);
}

bool ITCatTableBase::GetStyle(DWORD styleFlags) const
{
	DWORD currentStyle = GetProperty(ITCatTablePropertiesEnum::DWSTYLE);
	return (currentStyle & styleFlags) != 0;
}

void ITCatTableBase::SetBoolFlag(DWORD boolFlags)
{
    DWORD current = GetProperty(ITCatTablePropertiesEnum::DW_BOOL);
    SetProperty(ITCatTablePropertiesEnum::DW_BOOL, current | boolFlags);
}

void ITCatTableBase::ClearBoolFlag(DWORD boolFlags)
{
    DWORD current = GetProperty(ITCatTablePropertiesEnum::DW_BOOL);
    SetProperty(ITCatTablePropertiesEnum::DW_BOOL, current & ~boolFlags);
}

bool ITCatTableBase::GetBoolFlag(DWORD boolFlags)
{
    DWORD current = GetProperty(ITCatTablePropertiesEnum::DW_BOOL);
    return (current & boolFlags) != 0;
}

const wchar_t* ITCatTableBase::getText()
{
	return _Text.c_str();
}

void ITCatTableBase::setText(const wchar_t* text)
{
	_Text = text;
}

// 颜色设置和获取方法实现
void ITCatTableBase::SetBackgroundColor(COLORREF color)
{
	backgroundColor = color;
}

void ITCatTableBase::SetCustomTextColor(COLORREF color)
{
	textColor = color;
}

COLORREF ITCatTableBase::GetBackgroundColor() const
{
	return backgroundColor;
}

COLORREF ITCatTableBase::GetTextColor() const
{
	return textColor;
}

bool ITCatTableBase::HasCustomBackgroundColor() const
{
	return backgroundColor != CLR_INVALID;
}

bool ITCatTableBase::HasCustomTextColor() const
{
	return textColor != CLR_INVALID;
}
